package test;

import java.awt.Image;
import java.awt.image.ImageObserver;
import java.awt.image.PixelGrabber;

import javax.swing.ImageIcon;


public class conversor {

	public static void handlesinglepixel(int x, int y, int pixel) {
		int alpha = (pixel >> 24) & 0xff;
		int red   = (pixel >> 16) & 0xff;
		int green = (pixel >>  8) & 0xff;
		int blue  = (pixel      ) & 0xff;
		// Deal with the pixel as necessary...
	 }

	 public void handlepixels(Image img, int x, int y, int w, int h) {
		
	 }	
	
	 public static void main(String[] args){
		 
		 Image img = (new ImageIcon("E:\\bn.jpg")).getImage();
		 int x=0;
		 int y=0;


	    	
	        int w = img.getWidth(null);
	        int h = img.getHeight(null);
	        
	 		 int[] pixels = new int[w * h];
			//PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w);
			PixelGrabber pg = new PixelGrabber(img, 0, 0, w, h, true);
			try {
			    pg.grabPixels();
			} catch (InterruptedException e) {
			    System.err.println("interrupted waiting for pixels!");
			    return;
			}
			if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
			    System.err.println("image fetch aborted or errored");
			    return;
			}
			for (int j = 0; j < h; j++) {
			    for (int i = 0; i < w; i++) {
				handlesinglepixel(x+i, y+j, pixels[j * w + i]);
				System.out.println(pixels[j * w + i]+ " ");
			    }
			}
	 
	
	 }
}
